UnitCertificate = new Object();

var confirm_investments_store = Ext.create('Ext.data.Store', {
	fields : [ 'id', 'invenstmentCode', 'amount', 'status', 'postStatus', 'customer', 'customer_code', 'customer_name', 'fund_id', 'confirmDate', 'unitPrice', 'noOfUnits',
			'postAddress', 'active' ]
});

UnitCertificate.getCenterPanel = function() {

	grid = Ext.create('Ext.grid.Panel', {
		title : 'Investments',
		id : 'investment_grid',
		store : confirm_investments_store,
		height : 380,
		plugins : [ Ext.create('Ext.grid.plugin.CellEditing', {
			clicksToEdit : 1
		}) ],
		features : [ {
			ftype : 'summary'
		} ],
		columns : [ {
			header : 'Customer Code',
			dataIndex : 'customer_code',
			width : 100
		}, {
			header : 'Investment Code',
			dataIndex : 'invenstmentCode',
			width : 100
		}, {
			header : 'Amount',
			dataIndex : 'amount',
			width : 125,
			flex : 1,
			xtype : 'numbercolumn',
			format : '0,000.0000',
			align : 'right'
		}, {
			header : 'Address Type',
			dataIndex : 'postAddress',
			width : 150,
			align : 'center',
			editor : {
				xtype : 'combo',
				displayField : 'adrress',
				valueField : 'adrress',
				store : Ext.create('Ext.data.Store', {
					fields : [ 'adrress' ],
					data : [ {
						adrress : 'Corresponding Address'
					}, {
						adrress : 'General Address'
					} ]
				})
			}
		}, {
			xtype : 'actioncolumn',
			align : 'center',
			width : 80,
			items : [ {
				icon : 'images/view.png',
				handler : function(grid, rowIndex, colIndex) {
					var rec = grid.getStore().getAt(rowIndex);
					if (rec.get('id') != null) {
						var param = {
							'investment' : rec.get('id')
						};
						Report.OpenWindowWithPost('ReportServlet/unit_certificate', "width=1000, height=600, left=100, top=100,resizable=yes, scrollbars=yes", "NewFile", param);
					}
				}
			} ]
		}, {
			xtype : 'actioncolumn',
			width : 80,
			align : 'center',
			items : [ {
				icon : 'images/send2.png',
				handler : function(grid, rowIndex, colIndex) {
					var myMask = new Ext.LoadMask(formpanel, {
						msg : "Please wait..."
					});
					myMask.show();
					var rec = grid.getStore().getAt(rowIndex);
					Ext.Ajax.request({
						url : 'updateUCstatus.action',
						params : {
							"investment_id" : rec.get('id'),
							"addresType" : rec.get('postAddress')
						},
						success : function(response) {
							var obj = Ext.decode(response.responseText);
							confirm_investments_store.remove(rec);
							myMask.hide();
						}
					});
				}
			} ]
		} ]
	});

	return formpanel = Ext.create('Ext.form.Panel', {
		title : 'Investment Unit Cretificate Menagement',
		bodyPadding : 20,
		autoScroll : true,
		frame : true,
		defaults : {
			labelWidth : 110,
			anchor : '65%',
		},
		items : [ grid ],
		listeners : {
			render : function(p) {
				Ext.Ajax.request({
					url : 'getconfirmInvestment.action',
					success : function(response) {
						var obj = Ext.decode(response.responseText);
						confirm_investments_store.loadRawData(obj.investmentBeans);
					}
				});
			}
		}
	});

};
